#include "commons.h"
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BYTE read_memory( WORD address ) {
    switch( address ) {
        case 0x2000:
            return emu->ppu->open_bus;
        case 0x2001:
            return emu->ppu->open_bus;
        case 0x2002:
            return read_ppu_2002();
        case 0x2003:
            return emu->ppu->open_bus;
        case 0x2004:
            return emu->vram[ emu->ppu->sram_address ];
        case 0x2005:
            return emu->ppu->open_bus;
        case 0x2006:
            return emu->ppu->open_bus;
        case 0x2007:
            return read_ppu_2007( address );
        default:
            return emu->ram[ address ];
    }
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void write_memory( WORD address, BYTE value ) {
    switch( address ) {
        case 0x2000:
            emu->ppu->open_bus = value;
            write_ppu_2000( value );
            break;
        case 0x2001:
            emu->ppu->open_bus = value;
            write_ppu_2001( value );
            break;
        case 0x2002:
            emu->ppu->open_bus = value;
            break;
        case 0x2003:
            emu->ppu->open_bus = value;
            write_ppu_2003( value );
            break;
        case 0x2004:
            emu->ppu->open_bus = value;
            write_ppu_2004( value );
            break;
        case 0x2005:
            emu->ppu->open_bus = value;
            write_ppu_2005( value );
            break;
        case 0x2006:
            emu->ppu->open_bus = value;
            write_ppu_2006( value );
            break;
        case 0x2007:
            emu->ppu->open_bus = value;
            write_ppu_2007( value );
            break;
        default:
            emu->ram[ address ] = value;
            break;
    }
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////